Builder
Builds a PopupWidget from provided Elements and layout
All popups will come with a title widget Top Center of the layout. The next added element will key off this, or to manually layout off of it, use "title" as the element parent
Author
fzzyhmstrs
Since
0.2.0
Parameters
Text - the header title shown at the top of the popup
Int, optional - Defines the default horizontal padding between elements. Defaults to 4
Int, optional - Defines the default vertical padding between elements. Defaults to using the value from spacingW
Samples
import me.fzzyhmstrs.fzzy_config.screen.LastSelectable
import me.fzzyhmstrs.fzzy_config.screen.widget.LayoutWidget
import me.fzzyhmstrs.fzzy_config.screen.widget.PopupWidget
import me.fzzyhmstrs.fzzy_config.screen.widget.custom.CustomButtonWidget
import net.minecraft.client.MinecraftClient
import net.minecraft.client.gui.Element
import net.minecraft.client.gui.ParentElement
import net.minecraft.client.gui.widget.TextWidget
import net.minecraft.text.Text
import net.minecraft.util.Identifier
fun main() {
//sampleStart
// builds and pushes an example popup widget to a PopupParentElement
// start with the builder. The title will be displayed at the top of the popup like a windows window title
// dy default the horizontal and vertical padding will be 4px; it can be changed here too
val popup = PopupWidget.Builder(Text.translatable("my.cool.popup"))
//you can add horizontal dividers between content. it automatically justifies to the popup width
.addDivider()
//adds a basic element. give it a unique name, and position it
//this element is positioned below the last added element (the divider in this case), and aligned centered in the popup
.add("text_element", TextWidget(Text.translatable("my.cool.popup.text"), MinecraftClient.getInstance().textRenderer).alignCenter(),
LayoutWidget.Position.BELOW, LayoutWidget.Position.ALIGN_CENTER)
//adds a button, this element is below the "text_element" one, and aligned left in the popup bounds
.add("button_1", CustomButtonWidget.builder(Text.translatable("my.cool.popup.button1")) { b-> }.size(50, 44).build(),
LayoutWidget.Position.BELOW, LayoutWidget.Position.ALIGN_LEFT )
//a second button, this one is aligned horizontal to the top edge of the "button_1" element,
//aligns to the right of the widget window and is stretched to meet the closest element to its left ("button_1" in this case)
.add("button_2", CustomButtonWidget.builder(Text.translatable("my.cool.popup.button2")) { b-> }.size(50, 20).build(),
LayoutWidget.Position.ALIGN_RIGHT_AND_JUSTIFY, LayoutWidget.Position.HORIZONTAL_TO_TOP_EDGE)
//repeat that with button 3, this time aligned to "button_1" bottom edge
//this element has a defined parent (button_1), instead of automatically picking the last element
.add("button_3", CustomButtonWidget.builder(Text.translatable("my.cool.popup.button3")) { b-> }.size(50, 20).build(), "button_1",
LayoutWidget.Position.ALIGN_RIGHT_AND_JUSTIFY, LayoutWidget.Position.HORIZONTAL_TO_BOTTOM_EDGE)
//there is a special method for adding a "Done" button, this also takes "button_1" as its parent in this case
//it will automatically align below the parent element and justify across the entire width of the widget
.addDoneWidget(parent = "button_1")
//popups can be positioned relative to various contexts.
//in this case we are using the screen as context, positioning it 100px from the bottom right edge of the screen
//the context method will bound the popup within the screen if the widget is bigger than 100x100
.positionX(PopupWidget.Builder.screenContext{ w -> w - 100 })
.positionY(PopupWidget.Builder.screenContext{ h -> h - 100 })
//tells the popup to not render a blur behind it
.noBlur()
//clicking outside of this widget won't close it automatically (which is default behavior)
.noCloseOnClick()
//provide a custom background like so.
//make sure the texture is a nine-patch texture, and the popup will expect 8 pixels of border and padding before content
.background(Identifier.of("my_mod", "my_custom_background"))
//create the popup!
.build()
//Last step: push the popup to screen, the PopupWidget API will push the popup onto an open PopupParentElement screen, if any
PopupWidget.push(popup)
//sampleEnd
}
Types
A layout position to apply to a popup element
Functions
Adds an element, automatically keyed off the last added element (or "title" if this is the first added element). Uses the default padding.
Adds an element, keyed off a manually defined parent element. Uses the default padding.
Adds a horizontal divider below the last element, or defined parent
Adds a "Done" button below the previously added element, or below the defined parent
Adds a "Done" button below the previously added element, or below the defined parent
Adds an element, automatically keyed off the last added element (or "title" if this is the first added element). Uses the default padding.
Adds an element, keyed off a manually defined parent element. Uses the default padding.
Adds an element with custom vertical and horizontal padding, automatically keyed off the last added element (or "title" if this is the first added element)
Adds an element with custom vertical and horizontal padding, keyed off a manually defined parent element.
Adds an element with custom vertical padding, automatically keyed off the last added element (or "title" if this is the first added element)
Adds an element with custom vertical padding, keyed off a manually defined parent element.
Adds an element with custom horizontal padding, automatically keyed off the last added element (or "title" if this is the first added element)
Adds an element with custom horizontal padding, keyed off a manually defined parent element.
Appends a custom narration message to the end of the Popup title.
Defines a custom background texture for the popup. Should be a Nine Slice texture
Builds this builder
Defines a manual height for the widget. Will override any automatic sizing computations for height
The widget won't apply a layer of blur behind it when rendering.
The widget won't close if a click misses its bounding box. Normal behavior closes the popup on a missed click.
Defines an action to perform when this widget is clicked on. This will run before any click actions of child elements, and will not run at all if a suggestion window is open.
Defines an action to perform when this widget is closed
Pops a set of custom spacing off this widgets spacing stack. If all custom spacings are popped, will revert to the default spacing provided in the constructor
Defines the X positioner function for this widget, X being the left edge of the widget, border included.
Defines the Y positioner function for this widget, Y being the top edge of the widget, border included.
Push a custom element spacing to this widgets spacing stack. any elements added after this push will be spaced using the top h/w spacing on that stack, or the default spacing provided in the widget constructor if no custom spacing exists on the stack
Defines a manual width for the widget. Will override any automatic sizing computations for width